<template>
  <div>
    <nav-header :headerTitle="'商品详情'" :headerNext="''" :navBgColor="'#fff'"></nav-header>
    <section class="page">
      <div class="header">
        <img
          :ref="show.userInfo.avatarUrl"
          :src="loadingImg(show.userInfo.avatarUrl,1)"
          @error="errorImg(show.userInfo.avatarUrl,1)"
          alt
        />
        <span class="spanOne">{{show.userInfo.nickName}}</span>
        <span class="spanTwo">{{show.userInfo.brandName}}</span>
        <span class="spanThree" v-show="show.isSelf" v-on:click="contact">联系TA</span>
      </div>
      <div class="section">
        <div class="divOne">{{show.productInfo.productName}}</div>
        <div class="divTwo">{{show.productInfo.productBriefIntro}}</div>
        <img
          v-for="(items,index) in show.productInfo.productImgUrls"
          :key="index"
          :src="items"
          alt
        />
        <div class="divThree" v-show="!show.isSelf">
          <span class="spanOne"></span>
          <span class="spanTwo">以上信息由用户发布，不代表 BWRM平台意见，如有问题，请联系平台举报</span>
        </div>
        <div class="null120"></div>
      </div>
      <div class="footer">
        <div v-show="show.isSelf">
          <span class="spanOne" @click="delProduct(show.productInfo.id)">删除</span>
          <span class="spanTwo" @click="goUrl('editProduct',{productId:show.productInfo.id})">修改</span>
        </div>
        <div v-show="!show.isSelf">
          <div
            class="divOne"
            @click="goUrl('complaint',{tipOffSceneId:show.productInfo.id,tipOffScene:1})"
          >
            <div class="content">
              <img src="@/assets/images/good_disagree.png" alt />
              <span>违规举报</span>
            </div>
          </div>
          <div class="divTwo" v-on:click="contact">
            <div class="content">
              <img
                :src="show.userInfo.avatarUrl"
                alt
              />
              <span>联系TA</span>
            </div>
          </div>
        </div>
      </div>
    </section>
    <ModalDli
      :isModal.sync="ModalDli.isModal"
      :wxName.sync="ModalDli.wxName"
      :QQName.sync="ModalDli.QQName"
      :phone.sync="ModalDli.phone"
      @ModalDliClick="ModalDliClick"
    ></ModalDli>
  </div>
</template>
<script>
import Vue from "vue";
import { Toast } from "vant";
Vue.use(Toast);
import navHeader from "@/components/NavHeader";
import ModalDli from "@/components/ModalDli";
import mixin from "@/utils/mixin";
export default {
  name: "ProductDetail",
  mixins: [mixin],
  components: {
    navHeader,
    ModalDli
  },
  data() {
    return {
      show: {
        isSelf: true,
        userInfo: {
          avatarUrl: "",
          nickName: "",
          brandName: ""
        },
        productInfo: {
          id: "",
          productName: "",
          productBriefIntro: "",
          productImgUrls: []
        }
      },
      ModalDli: {
        isModal: false,
        wxName: "",
        QQName: "",
        phone: ""
      }
    };
  },
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.params = {
        productId: this.$route.query.productId,
        uniqueId: window.localStorage.uniqueId
      };
      this.$http.post("product/getProductInfo", this.params).then(
        res => {
          res = res.data;
          this.show = res;
          if (res.curUniqueId == res.userInfo.uniqueId) {
            this.show.isSelf = true;
          } else {
            this.show.isSelf = false;
          }
        },
        err => {
          console.log(err);
        }
      );
    },
    contact: function() {
      let data = window.localStorage.getItem("ModalDli");
      let res = JSON.parse(data);
      this.ModalDli.wxName = res.wxName;
      this.ModalDli.QQName = res.QQName;
      this.ModalDli.phone = res.phone;
      this.ModalDli.isModal = true;
      //console.log(this.ModalDli);
    },
    ModalDliClick: function() {},
    delProduct(id) {
      this.params = {
        productId: id
      };
      this.$http.post("product/removeProductInfo", this.params).then(
        res => {
          console.log(res);
          Toast.success({
            forbidClick: true,
            message: "删除成功",
            onClose: () => {
              this.$router.go(-1); //返回上一层
            }
          });
        },
        err => {
          console.log(err);
        }
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.page {
  margin-top: 86px;
  .null120 {
    width: 100%;
    height: 120px;
  }
  .header {
    width: 100%;
    height: 200px;
    position: relative;
    img {
      width: 128px;
      height: 128px;
      border-radius: 50%;
      position: absolute;
      left: 30px;
      top: 24px;
    }
    .spanOne {
      font-size: 40px;
      font-family: PingFangSC-Medium;
      font-weight: bold;
      color: rgba(48, 49, 51, 1);
      position: absolute;
      left: 190px;
      top: 40px;
    }
    .spanTwo {
      font-size: 30px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(129, 129, 129, 1);
      position: absolute;
      left: 190px;
      top: 100px;
    }
    .spanThree {
      width: 188px;
      height: 64px;
      line-height: 64px;
      text-align: center;
      background: rgba(255, 37, 37, 1);
      border-radius: 8px;
      font-size: 32px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      color: rgba(255, 255, 255, 1);
      position: absolute;
      right: 32px;
      top: 56px;
    }
  }
  .section {
    margin-left: 30px;
    margin-right: 30px;
    text-align: left;
    .divOne {
      width: 100%;
      // height: 56px;
      font-size: 40px;
      font-family: PingFangSC-Medium;
      font-weight: bold;
      color: rgba(48, 49, 51, 1);
      margin-bottom: 24px;
    }
    .divTwo {
      width: 100%;
      // height: 192px;
      font-size: 32px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(48, 49, 51, 1);
      margin-bottom: 24px;
      line-height: 48px;
    }
    img {
      width: 100%;
      height: 686px;
      margin-bottom: 32px;
    }
    .divThree {
      width: 100%;
      height: 84px;
      position: relative;
      .spanOne {
        width: 14px;
        height: 14px;
        background: rgba(255, 37, 37, 1);
        border-radius: 50%;
        position: absolute;
        top: 16px;
        left: 0px;
      }
      .spanTwo {
        width: 661px;
        height: 84px;
        text-align: left;
        font-size: 28px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        color: rgba(129, 129, 129, 1);
        line-height: 42px;
        position: absolute;
        left: 26px;
        top: 0px;
      }
    }
  }
  .footer {
    width: 100%;
    height: 120px;
    position: fixed;
    bottom: 0px;
    background: #fff;
    .spanOne {
      width: 328px;
      height: 88px;
      line-height: 88px;
      text-align: center;
      background: rgba(255, 37, 37, 1);
      border-radius: 44px;
      font-size: 34px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      color: rgba(255, 255, 255, 1);
      position: absolute;
      left: 32px;
      top: 16px;
    }
    .spanTwo {
      width: 328px;
      height: 88px;
      line-height: 88px;
      text-align: center;
      background: rgba(122, 95, 229, 1);
      border-radius: 44px;
      font-size: 34px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      color: rgba(255, 255, 255, 1);
      position: absolute;
      right: 32px;
      top: 16px;
    }
    .content {
      width: 100%;
      height: 100%;
      position: relative;
    }
    .divOne {
      width: 100px;
      height: 79px;
      position: absolute;
      left: 31px;
      top: 22px;
      span {
        font-size: 24px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        color: rgba(255, 37, 37, 1);
        position: absolute;
        left: 0px;
        top: 45px;
      }
      img {
        width: 42px;
        height: 42px;
        position: absolute;
        left: 29px;
        top: 0px;
      }
    }
    .divTwo {
      width: 243px;
      height: 86px;
      position: absolute;
      top: 16px;
      right: 32px;
      img {
        width: 82px;
        height: 82px;
        position: absolute;
        left: 0px;
        top: 0px;
        border: 2px solid rgba(255, 37, 37, 1);
        border-radius: 50%;
        z-index: 200;
      }
      span {
        width: 150px;
        padding-left: 50px;
        height: 64px;
        text-align: center;
        line-height: 64px;
        background: rgba(255, 37, 37, 1);
        border-radius: 8px;
        position: absolute;
        left: 42px;
        bottom: 0px;
        font-size: 32px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        color: rgba(255, 255, 255, 1);
      }
    }
  }
}
</style>
